package com.example.cardgame

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.cardgame.R
import com.example.cardgame.databinding.ActivitySecondBinding

var KEY2="key2"
class SecondActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySecondBinding
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_second)
        binding = ActivitySecondBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val button=findViewById<TextView>(R.id.start_game)
        button.setOnClickListener {
            val intent = Intent(this, FirstActivity::class.java)
            startActivityForResult(intent,1)
        }
        val button2=findViewById<TextView>(R.id.fix)
        button2.setOnClickListener {
            val intent = Intent(this, FirstActivity::class.java)
            startActivityForResult(intent,2)
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode==2){
            if (resultCode== 1){
                data?.let {
                    val name=findViewById<TextView>(R.id.name2)
                    val sex=findViewById<TextView>(R.id.sex)
                    val id=findViewById<TextView>(R.id.id)
                    val number=findViewById<TextView>(R.id.Number)
                    val email=findViewById<TextView>(R.id.email)
                    val hobby=findViewById<TextView>(R.id.Hobby)
                    name.text="姓名: "+data.getStringExtra("name")
                    sex.text="性别: "+data.getStringExtra("sex")
                    id.text="学号: "+data.getStringExtra("id")
                    number.text="电话: "+data.getStringExtra("number")
                    email.text="邮箱: "+data.getStringExtra("email")
                    hobby.text="爱好: "+data.getStringExtra("hobby")
                }
            }
        }
    }
}


